﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public delegate void TickHandler(int Time);
   
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
            
        }

        public void OnTickHandler(int Time) 
        {
            label1.Text = Convert.ToString(Time);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Interpolator ob = new Interpolator(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox3.Text));
            ob.TH += new TickHandler(OnTickHandler);        
            ob.Start();
    //        label1.Text = Convert.ToString(Interpolator.test);
             

        }
    }

    class Interpolator
    {
   //     private TickHandler TH;
        private int iFrst, iScnd, iTime;
        public static int test;
        public System.Windows.Forms.Timer aTimer;

        public event TickHandler TH;

        public Interpolator(int i, int x, int y)
        {
            iFrst = i;
            iScnd = x;
            iTime = y;
            test = 0;
        //    TH = new TickHandler
        }

        public void Start()
        {
            aTimer = new System.Windows.Forms.Timer();
            aTimer.Interval = (iTime * 1000);
            aTimer.Tick += new EventHandler(OnTick);
            aTimer.Start();
        }


        //public void Add_onTick(TickHandler deleg)
        //{
        //    TH += deleg;
        //}


        public void OnTick(object sender, EventArgs e)
        {
            test = Calculate();
            TH(test);
        }

        public int Calculate()
        {
            return (test + 10);
        }
    }
}
